package ch1strings;

public class Ex6 {
	static int [][] rotate(int [][] input) {
		int [][] newMat = new int [input.length][input.length];
		int n=input.length;
		for (int i=0; i<n; i++) {
			for (int j=0; j<n; j++) {
				newMat[j][n-i-1] = input[i][j];
			}
		}
		return newMat;
	}
	
	public static void main(String ...strings) {
		int [][] mat = new int [][] {
				{1, 2, 3, 4},
				{5, 6, 7, 8},
				{9, 10, 11, 12},
				{13, 14, 15, 16},
		};
		printMat(mat);
		int[][] rotate = rotate(mat);
		printMat(rotate);
	}

	static void printMat(int [][] mat) {
		for (int [] row : mat) {
			for (int col : row) {
				System.out.print(col+"\t");
			}
			System.out.println();
		}
		System.out.println();
	}
}
